﻿{extend name="layout/layout" /}
<!--请在下方写此页面body相关内容-->
{block name="container"}
<article class="page-container">
	<form action="<?php echo url('group/groupSave')?>" method="post" class="form form-horizontal" id="form" >
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>用户组名称：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" placeholder="" id="group_name" name="group_name">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>用户组权限：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<?php foreach($list as $k=>$v){ if($v['pid'] == 0){ ?>
				<dl class="permission-list">
					<dt>
						<label><input type="checkbox" value="<?php echo $v['id']?>" name="auth_ids[]" id="user-Character-1">
							<?php echo $v['rule_name']?>
						</label>
					</dt>
					<dd class="cl permission-list2">
						<?php foreach($list as $v1){ if($v['id'] == $v1['pid']){ ?>
						<dl style="min-height: 20px">
							<dt>
								<label>
									<input type="checkbox" value="<?php echo $v1['id']?>" name="auth_ids[]" id="user-Character-0-0">
									<?php echo $v1['rule_name']?>
								</label>
							</dt>
							<dd>
								<?php foreach($list as $v2){ if($v1['id'] == $v2['pid']){ ?>
								<label>
									<input type="checkbox" value="<?php echo $v2['id']?>" name="auth_ids[]" id="user-Character-0-0-0">
									<?php echo $v2['rule_name'] ?>
								</label>
								<?php } }?>
							</dd>
						</dl>
						<?php } }?>
					</dd>
				</dl>
				<?php } }?>
			</div>
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
				<input type="hidden" name="pid" value="<?php echo $info['id']?>">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
			</div>
		</div>
	</form>
</article>
{/block}
<!--请在上方方写此页面body相关内容-->

<!--请在下方写此页面业务相关的脚本-->
{block name="js"}
<script type="text/javascript">
$(function(){
    $(".permission-list dt input:checkbox").click(function(){
        $(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
    });
    $(".permission-list dd dt input:checkbox").click(function(){
        var l  = $(this).parent().parent().find("input:checked").length;
        var l2 = $(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
        if($(this).prop("checked")){
            $(this).closest("dl").find("dt input:checkbox").prop("checked",true);
            $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
        } else {
            if(l === 0) $(this).closest("dl").find("dt input:checkbox").prop("checked",false);
            if(l2 === 0) $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",false);
        }
    });
    $(".permission-list2 dd input:checkbox").click(function(){
        if($(this).prop("checked")){
            $(this).closest("dl").find("dt input:checkbox").prop("checked",true);
            $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
        }
    });

	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-yellow',
		increaseArea: '20%'
	});

	$("#form").validate({
		rules:{
			group_name:{required:true}
		},
		submitHandler:function(form){
			var options = {
                beforeSubmit: function () {
                    load = layer.load();
                },
                success: function(obj){
                    if(obj.code !== 0){
                        layer.msg(obj.msg,{ icon:5, time:2000 });
                    } else {
                        layer.msg(obj.msg, { icon: 1, time: 2000 }, function(){
                            closeWindow();
                        });
                    }
                    layer.close(load);
                }
			};
			$(form).ajaxSubmit(options);
		}
	});
});
</script>
{/block}
<!--/请在上方写此页面业务相关的脚本-->